package main

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func hasPathSum(root *TreeNode, targetSum int) bool {
	return preOrder112(root, 0, targetSum)
}

func preOrder112(root *TreeNode, sum, target int) bool {
	if root == nil {
		return false
	}
	sum += root.Val
	if sum == target && root.Left == nil && root.Right == nil {
		return true
	}
	return preOrder112(root.Left, sum, target) || preOrder112(root.Right, sum, target)
}
